package com.riant.test8;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Test3 {
    public static void main(String[] args) {
        searchChineseCharacter("Good morning");
        searchChineseCharacter("早上好hello 早上好氮䓬斯汀");
    }

    public static void searchChineseCharacter(String str) {
        //正则表达式，用于匹配中文字符
        String regex = "[\u4e00-\u9fa5]";
        //如果str的长度和其所占字节数不等，说明包含中文
        if (str.length() != str.getBytes().length) {
            Pattern pattern = Pattern.compile(regex);
            Matcher matcher = pattern.matcher(str);
            System.out.print("'" + str + "' 中的汉字为:");
            while (matcher.find()) {
                System.out.print(matcher.group());
            }
        } else {
            System.out.println("'" + str + "' 中无汉字");
        }
    }
}
